package iss.java;
import iss.java.list.Mylist;
import iss.java.list.Node;
import java.util.*;
/**
 * Created by wenke on 2016/9/16.
 */
public class Main_B {
    public static void main(String[] args) {
        // TODO: Write a multithreaded testcase against requirement B.
        // NOTE: Testcase for requirement C is not required.
        Mylist list = new Mylist();
        Node node = list.getHead();

        InsertThread l1 = new InsertThread(list, node, 10);
        InsertThread l2 = new InsertThread(list, node, 11);
        InsertThread l3 = new InsertThread(list, node, 12);

        Thread i1 = new Thread(l1);
        Thread i2 = new Thread(l2);
        Thread i3 = new Thread(l3);

        i1.start();
        i2.start();
        i3.start();

        Thread.sleep(2000);
        list.forwardPrint();
        list.backwardPrint();

        Node node1 = list.getHead().getNext();
        Node node2 = list.getHead().getNext().getNext();
        RemoveThread r1 = new RemoveThread(list, node1);
        RemoveThread r2 = new RemoveThread(list, node2);
        Thread rt1 = new Thread(r1);
        Thread rt2 = new Thread(r2);
        rt1.start();
        rt2.start();

    }
}
class WriteThread implements Runnable{
    private int number;
    private Node node;
    private Mylist list;

    InsertThread(Mylist list,Node node,int num){
        this.number = number;
        this.node = node;
        this.list = list;
    }
    public void run(){
        list.insert(node,num);
    }
}
class RemoveThread implements Runnable{
    private Node node;
    private MyList list;

    RemoveThread(MyList list, Node node) {
        this.node = node;
        this.list = list;
    }
    public void run(){
        list.remove(node);
    }
}

